﻿const TOOLBAR = [{
	content: "下载",
	icon: "el-icon-download",
	type: "primary"
}]
const COLUMNS = [
    {
		prop: "id",
		label: "流转单号",
		width: "80"
	},
    {
		prop: "mycustomerid",
		label: "销售单号",
		width: "80"
	},
	{
		prop: "transdate",
		label: "流转日期",
		width: "100"
	},
	{
		prop: "compname",
		label: "公司名称",
		width: "120"
	},
	{
		prop: "contacter",
		label: "联系人",
		width: "80"
	},
	{
		prop: "phone",
		label: "电话",
		width: "100"
	},
	{
		prop: "collectiondate",
		label: "收款日期",
		width: "100"
	},
	{
		prop: "amountreceivables",
		label: "应收金额",
		width: "100"
	},
	{
		prop: "sellername",
		label: "销售",
		width: "80"
	},
	{
		prop: "handovername",
		label: "交接人",
		width: "80"
	},
	{
		prop: "status",
		label: "状态",
		width: "80"
	},
	{
		prop: "formtype",
		label: "流转类型",
		width: "80"
	},
	{
		prop: "memo",
		label: "备注",
		width: "100"
	}
]
const COLUMNS_EXP = [
	{prop:"service", label:"办理业务",style:"width:100%"},
	{prop:"recorder", label:"收款记录",style:"width:100%"},
	{prop:"outformername", label:"出单人",style:"width:25%"},
	{prop:"src", label:"来源",style:"width:25%"},
	{prop:"area", label:"区域",style:"width:25%"},
	{prop:"addresstype", label:"地址类型",style:"width:25%"},
	{prop:"invoicingtype", label:"开票类型",style:"width:25%"},
	{prop:"amountinvoicing", label:"开票金额",style:"width:25%"},
	{prop:"taxtype", label:"税务类型",style:"width:25%"},
	{prop:"preferentialdescription", label:"优惠单",style:"width:25%"},
	{prop:"oldprice", label:"优惠前金额",style:"width:25%"},
	{prop:"newprice", label:"优惠后金额",style:"width:25%"},
	{prop:"gifts", label:"赠送情况",style:"width:25%"},
	{prop:"signtype", label:"签约方式",width:"80"},
	{prop:"amounttotal", label:"合计金额",style:"width:25%"},
	{prop:"amountreceivables", label:"应收",style:"width:25%"},
	{prop:"amountpayin", label:"实收",style:"width:25%"},
	{prop:"amountend", label:"尾款",style:"width:25%"},
	{prop:"amountendcondition", label:"尾款条件",style:"width:25%"},
	{prop:"supervisorname", label:"主管",style:"width:25%"},
	{prop:"financename", label:"财务",style:"width:25%"},
	{prop:"receivername", label:"接收人",style:"width:25%"},
	{prop:"materials", label:"相关材料",style:"width:100%"},
	{prop:"annex", label:"附件",style:"width:100%"},
	
]
transFormRecorderRules = {
	collectiondate: [
	    {required: true, message: '请输入收款日期', trigger: 'blur'}
	],
	loantype: [
	    {required: true, message: '请输入收款方式', trigger: 'blur'}
	],
	totalprice: [
	    {required: true, message: '请输入现收尾款', trigger: 'blur'}
	],
	amountpayin: [
	    {required: true, message: '请输入实收金额', trigger: 'blur'}
	],
}
let validate = {
	validatePass: (rule, value, callback) => {

	}
};

let app = new Vue({
	el: "#app",
	data() {
		return {
			leaders: [],
			serviceCheckForm: {

			},
			form: {
				tableData: []
			},
			rules: {
				leader: [{
					required: true,
					message: "主管人不能为空",
					trigger: "blur"
				}],
				enddate: [{
					required: true,
					message: "服务期限不能为空",
					trigger: "blur"
				}],
			},
			leftbar_show: true,
			// 添加、编辑标识
			action: "",
			tabvalue: "base",
			tableHeight: window.innerHeight - 180,
			toolbar: TOOLBAR,
			tablecolums: COLUMNS,
			tablecolumsexp: COLUMNS_EXP,
			detailcolums: [{
					"prop": "name",
					"label": "名称",
					"width": "100"
				},
				{
					"prop": "spec",
					"label": "规格",
					"width": "150"
				},
				{
					"prop": "type",
					"label": "类别",
					"width": "150"
				},
				{
					"prop": "amount",
					"label": "数量",
					"width": "50"
				},
				{
					"prop": "unit",
					"label": "单位",
					"width": "50"
				},
				{
					"prop": "price",
					"label": "单价",
					"width": "100"
				},
				{
					"prop": "totalprice",
					"label": "服务金额",
					"width": "100"
				},
				//{
				//	"prop": "cost",
				//	"label": "成本金额",
				//	"width": "100"
				//},
				{
					"prop": "items",
					"label": "服务项目",
					"width": "250"
				},
				{
					"prop": "memo",
					"label": "备注",
					"width": "220"
				}
			],
			distridetailcolums: [{
					"prop": "name",
					"label": "名称",
					"width": "80"
				},
				{
					"prop": "spec",
					"label": "规格",
					"width": "60"
				},
				{
					"prop": "type",
					"label": "类别",
					"width": "60"
				},
				{
					"prop": "amount",
					"label": "数量",
					"width": "50"
				},
				{
					"prop": "unit",
					"label": "单位",
					"width": "50"
				},
				{
					"prop": "items",
					"label": "服务项目",
					"width": "80"
				},
				{
					"prop": "memo",
					"label": "备注",
					"width": "80"
				},
			],
			recordercolums:[
				{"prop":"collectiondate", "label":"收款日期","width":"100"},
				{"prop":"totalprice", "label":"收款金额","width":"100"},
				{"prop":"reciver", "label":"收款人","width":"100"},
				{"prop":"loantype", "label":"收款类型","width":"100"},
				{"prop":"memo", "label":"备注","width":"150"}
			],
			dialogFormVisible:false,
			dialogTransFormDetailVisible:false, 
			dialogDistriFormVisible:false,
			uploadurl:axios.defaults.baseURL + "api/transform/annex/upload/",
			// 上传收款截图
			uploadrecorderurl:axios.defaults.baseURL + "api/transformrecorder/annex/upload/",
			userid:	localStorage.getItem('USERID'),
			dialogFormVisible: false,
			downloadDialogVisible: false,
			dialogTransFormDetailVisible: false,
			dialogDistriFormVisible: false,
			dialogAuditFormVisible: false,
			dialogNoPassFormVisible: false,
			transFormRecorderVisible:false,
			imgdialogVisible: false,
			imgdialogImageUrl :"",
			userid: localStorage.getItem('USERID'),
			headers: {
				Token: localStorage.getItem('TOKEN'),
				UserID: localStorage.getItem('USERID')
			},
			queryForm: {
				userid: localStorage.getItem('USERID'),
				keyword: "",
				personnel: "",
				signtype: [],
				status: ['待审核','已审核','已分配','已流转'],
				datetime: [],
				formtype: [], // 流转类型
				endedamount:[], // 尾款是否结清
				pageNo: 1, // 当前页码
				pagesize: 100, // 每页记录数
				pagesizes: [10, 20, 50, 100, 500]
			},
			pagetotal: 0,
			pickerOptions: {
				shortcuts: [{
					text: '最近一周',
					onClick(picker) {
						const end = new Date()
						const start = new Date()
						start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
						picker.$emit('pick', [start, end])
					}
				}, {
					text: '最近一个月',
					onClick(picker) {
						const end = new Date();
						const start = new Date();
						start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
						picker.$emit('pick', [start, end]);
					}
				}, {
					text: '最近三个月',
					onClick(picker) {
						const end = new Date();
						const start = new Date();
						start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
						picker.$emit('pick', [start, end]);
					}
				}]
			},
			tempfilelist: [],
			downloadForm: {
			},
			mycustomerid:0,
            transForm: {
                id: null,
				mycustomerid: null,
                compname: "",
                legalperson: "",
				contacter:"",
                phone: "",
                address: "",
                area: "",
				src:"",
				status:"",
				business:"",
				collectiondate:"",
				transdate:"",
				treasurer:"",
				supervisor:"",
				servicedate:"",
				sellerid:"",
				sellername:"",
				outformerid:"",
				outformername:"",
				src:"",
				area:"",
				addresstype:"",
				invoicingtype:"",
				amountinvoicing:"",
				taxtype:"",
				gifts:"",
				paytype:"",
				amountreceivables:"",
				amountpayin:"",
				amountend:"",
				amountendcondition:"",
				financeid:"",
				financename:"",
				financestatus:"",
				materials:[],
				annex:[],
				handoverid:"",
				handovername:"",
				receiverid:"",
				receivername:"",
				supervisorid:"",
				supervisorname:"",
				memo:"",
				discount_id:"",
				oldprice:0,
				newprice:0,
				recorder:[]
            },
			serviceForm: {
				transformid: 0,
				customerid: 0,
				service: [],
				remark:""
			},
			transFormDetail: {
				name: "",
				spec: "",
				type: "",
				amount: 0,
				unit: "",
				cost: 0,
				price: 0,
				totalprice: 0,
				memo: "",
				service: []
			},
			transFormRecorder:{
				id:0,
				transformid:0,
				collectiondate:'',
				amountreceivables:0,
				amountpayin:0,
				totalprice:0,
				loantype:'',
				annex:[],
				memo:""
			},
			noPassForm: {
				memo: ""
			},
			// 所有用户
			users: [],
			variable: [],
			members: [],
			//工商组
			bussinessmembers:[],
			//财税组
			taxationmembers:[],
			// 来源
			sources: ["新签", "续签", "线索", "渠道"],
			signtypes: ["新签", "续签", "转介绍"],
			invoicingtypes: ["增值税普通发票", "增值税专用发票", "不开票"],
			taxtypes: ["小规模", "小规模+票", "一般纳税人", "一般纳税人+票","个体", "上门服务"],
			materialslist: ["营业执照 正本原件/复印件", "准予设立通知书", "房产证 原件/复印件", "租赁合同 原件/复印件", "场地使用证明",
				"银行回单卡", "基本存款信息表（开户许可证）原件/复印件", "法人身份证原件/复印件", "股东身份证原件/复印件", "监事身份证原件/复印件", "财务身份证原件/复印件",
				"公章", "发票章", "财务章", "法人章", "合同章", "报税CA", "UKEY", "税控盘", "空白发票", "发票领购簿", "财务报表 （资产负债表、现金流量表、利润表）", "其他资料"
			],
			addresstypes: ["自有地址", "挂靠地址"],
			allstatus: ["待审核", "已审核", "已分配",'已流转', "已驳回"],
			loantypes:['支付宝','微信','对公','现金'],
			formtypes:['正常流转','尾款流转'],
			endedamounts:['是','否'],
			//服务项目列表
			services: [],
			// 指定客户的优惠单
			discountlist:[],
			// 多选
			multipleSelection: [],
			pagedata: [], // 当前页结果集
			loaded: false,
		}
	},
	methods: {
		// 显示侧边栏
		showLeftBar() {
			if (this.leftbar_show) {
				this.leftbar_show = false
			} else {
				this.leftbar_show = true
			}
		},
		// 表格多选 
		handleSelectionChange(val) {
			this.multipleSelection = val;
		},

		handleRemove(file, filelist) {
			this.createTempfilelist(filelist);
		},
		handledownloadPreview(file) {
			this.downloadFile(file.name)
		},
		handleAvatarSuccess(res, file, filelist) {
			this.createTempfilelist(filelist);
		},
		beforeAvatarUpload(file) {
			const isLt20M = file.size / 1024 / 1024 < 20;
			if (!isLt20M) {
				this.$message.error('上传图片大小不能超过 20MB!');
				return false;
			}
			return true;
		},
		createTempfilelist(filelist) {
			this.tempfilelist = []
			for (let s of filelist) {
				if (typeof(s.response) != "undefined") {
					this.tempfilelist.push({
						name: s.response.data.name,
						url: s.response.data.url + "?" + localStorage.getItem('TOKEN')
					});
				} else {
					this.tempfilelist.push({
						name: s.name,
						url: s.url
					});
				}
				index = this.tempfilelist[0].name.lastIndexOf('.');
				this.tempfilelist[0].suffix = this.tempfilelist[0].name.substring(index + 1);
				//this.tempfilelist.suffix = this.tempfilelist.substring(0,index);
			}
		},
		
		handledownloadPreview4annex(file) {
			//this.imgdialogImageUrl = file.url;
			//this.imgdialogVisible = true;
		},
		handleRemove4annex (file, filelist) {
			this.transFormRecorder.annex = this.createAnnexfilelist(filelist);
		},

		handleAvatarSuccess4annex(res, file, filelist) {
			this.transFormRecorder.annex = this.createAnnexfilelist(filelist);
		},
		
		createAnnexfilelist(filelist) {
			var tempfilelist = []
			for (let s of filelist) {
				if (typeof(s.response) != "undefined") {
					tempfilelist.push({
						name: s.response.data.name,
						url: s.response.data.url
					});
				} else {
					tempfilelist.push({
						name: s.name,
						url: s.url
					});
				}
			}
			return tempfilelist;
		},

		// 服务项目变化时
		async servicechange(id) {
			// 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
				let res = await axios.get('api/servicedetail/get/' + id);
				if (res.code === 200) {
					this.transFormDetail.service = res.data;
					if (this.transFormDetail.service.length > 0) {
						this.transFormDetail.amount = 1
						this.transFormDetail.name = this.transFormDetail.service[0].name
						this.transFormDetail.price = this.transFormDetail.service[0].price
						this.transFormDetail.totalprice = this.transFormDetail.service[0].price * this.transFormDetail.amount
						this.transFormDetail.unit = this.transFormDetail.service[0].unit
						this.transFormDetail.spec = this.transFormDetail.service[0].spec
						this.transFormDetail.type = this.transFormDetail.service[0].type
						this.transFormDetail.cost = this.transFormDetail.service[0].cost * this.transFormDetail.amount
						this.transFormDetail.items = this.transFormDetail.service[0].items
						this.transFormDetail.memo = this.transFormDetail.service[0].memo
					} else {
						this.transFormDetail.amount = 1
						this.transFormDetail.name = this.transFormDetail.name
						this.transFormDetail.price = 0
						this.transFormDetail.totalprice = 0
						this.transFormDetail.unit = "无"
						this.transFormDetail.spec = "无"
						this.transFormDetail.type = "无"
						this.transFormDetail.cost = 0
						this.transFormDetail.items = ""
						this.transFormDetail.memo = ""
					}
				} else {
					this.$message.error(res.message);
				}
			} catch (e) {
				this.$message.error('服务项目请求出错！', e.message);
			}

			// 关闭加载框
			loading.close();
		},
		serviceDetailClick(row, column, event) {
			this.transFormDetail.amount = 1
			this.transFormDetail.name = row.name
			this.transFormDetail.price = row.price
			this.transFormDetail.unit = row.unit
			this.transFormDetail.spec = row.spec
			this.transFormDetail.type = row.type
			this.transFormDetail.cost = row.cost
			this.transFormDetail.items = row.items
			this.transFormDetail.memo = row.memo

		},
		// 添加服务
		addService() {
			this.action = "adddetail";
			this.dialogTransFormDetailVisible = true
			this.transFormDetail.name = ""
			this.transFormDetail.amount = 0
			this.transFormDetail.unit = ""
			this.transFormDetail.cost = 0
			this.transFormDetail.price = 0
			this.transFormDetail.totalprice = 0
			this.transFormDetail.memo = ""
			this.transFormDetail.service = []
		},
		// 编辑服务
		editService(index, row) {
			this.action = "editdetail"
			this.dindex = index;
			this.dialogTransFormDetailVisible = true
			this.transFormDetail = deepCopy(row)
		},
		// 删除服务
		delService(index, row) {
			this.transForm.service.splice(index, 1)
		},
		//确认分配信息
		async cofirmdistribute() {
			this.$refs.serviceCheckForm.validate(async valid => {
				if (valid) {
					const loading = this.$loading(LOAD_STYLE);
					try {
						let res = await axios.post('api/transformdetail/assignment', this.serviceForm);
						console.log(res)
						if (res[0].code === 200) {
							this.$message.success(res[0].message);
							this.query()
						} else {
							this.$message.error(res[0].message);
						}
					} catch (e) {
						this.$message.error('请求出错！', e.message);
					}
					// 关闭加载框
					loading.close();
					this.dialogDistriFormVisible = false;

				}
			})
		},
		// 确认添加，编辑服务信息
		confirmService() {
			this.$refs.transFormDetail.validate(async valid => {
				if (valid) {
					let res = null;
					if (this.action == "adddetail") {
						// 添加服务
						this.transForm.service.push(deepCopy(this.transFormDetail))
					} else if (this.action == "editdetail") {
						// 编辑服务
						this.transForm.service[this.dindex].name = this.transFormDetail.name
						this.transForm.service[this.dindex].unit = this.transFormDetail.unit
						this.transForm.service[this.dindex].time = this.transFormDetail.time
						this.transForm.service[this.dindex].cost = this.transFormDetail.cost
						this.transForm.service[this.dindex].price = this.transFormDetail.price
					}
					sum = 0
					for (let row of this.transForm.service) {
						sum = sum + row.price * 1
					}
					this.transForm.amounttotal = sum
					this.dialogTransFormDetailVisible = false
				} else {

				}
			})
		},
		downloadRecorderAnnex(url) {
			this.imgdialogImageUrl = url;
			this.imgdialogVisible = true;
		},
		//下载流传单附件
		async downloadFile(filename){
			this.downloadForm.downloadname = filename;
			this.downloadForm.token = localStorage.getItem('TOKEN');
			 let res = await axios.post('api/transform/annex/download',this.downloadForm,'blob')
			 if(res){
			  const blData = res //拿到blob数据
			  const urlObjData = window.URL.createObjectURL(new Blob([res]))
			  //获取文件 进行下转码	  
			  const fileName = this.downloadForm.downloadname
			   
			  //创建a标签 点击a标签 达到下载目的
			  const link = document.createElement('a')
			  link.href = urlObjData
			  link.download = fileName //下载文件的名字
			  document.body.appendChild(link)
			  link.click()
			   
			  document.body.removeChild(link)
			  window.URL.revokeObjectURL(urlObjData);
			   
			 }
		},
		// 驳回
		async nopass() {
			// 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
				this.$confirm('确定要驳回当前流转单吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(async () => {
					if (this.transForm.memo == '') {
						this.$message.error('请填写驳回理由！');
					} else {
						// 驳回
						this.transForm.userid = localStorage.getItem('USERID');
						let res = await axios.put('api/transform/nopass', this.transForm);
						if (res.code === 200) {
							this.query();
							this.dialogNoPassFormVisible = false
							this.$message.success(res.message);
						} else {
							this.$message.error(res.message);
						}
					}
				}).catch((e) => {
					if (e.message) this.Msg('error', e.message);
				});
			} catch (e) {
				this.$message.error('驳回出错！', e.message);
			}
			// 关闭加载框
			loading.close();

		},

		// 审核通过
		async cofirm() {
			//this.$refs.transForm.validate(async valid => {
			//	if (valid) {
					// 显示加载框
					const loading = this.$loading(LOAD_STYLE);
					try {
						// 审核
						this.transForm.userid = localStorage.getItem('USERID');
						let res = await axios.put('api/transform/audit', this.transForm);
						if (res.code === 200) {
							this.$message.success(res.message);
							this.query();
							this.dialogAuditFormVisible = false
						} else {
							this.$message.error(res.message);
						}

					} catch (e) {
						this.$message.error('审核出错！', e.message);
					}
					// 关闭加载框
					loading.close();
		//		}
		//	})
		},
		start() {
			this.queryForm.pageNo = 1
			this.query()
		},
		// 查询
		async query() {
			// 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
				let res = await axios.post('api/transform/query', this.queryForm);
				if (res.code === 200) {
					this.pagedata = res.data;
					this.pagetotal = res.total;
					this.$message.success(res.message);
				} else {
					this.$message.error(res.message);
				}
			} catch (e) {
				this.$message.error('查询请求出错！', e.message);
			}

			// 关闭加载框
			loading.close();
		},
		//初始化会计部的子部门用户列表
		async getAccountant() {
			// 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
				let res = await axios.get('api/user/accountant');
				if (res.code === 200) {
					console.log(res)
					this.members = res.data
				} else {
					this.$message.error(res.message);
				}
			} catch (e) {
				this.$message.error('取得会计部的子部门用户列表请求出错！', e.message);
			}

			// 关闭加载框
			loading.close();
			this.members.map((item, index) => {
				if (item.deptname == "财税部") {
					for (useritem in item.users) {
						this.taxationmembers.push(
							Object.assign(item.users[useritem])
						)
					}
				}
				else if (item.deptname == "工商部") {
					for (useritem in item.users) {
						this.bussinessmembers.push(
							Object.assign(item.users[useritem])
						)
					}
				}
			});

		},
		// 取得所有用户列表
		async getAllUser() {
			// 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
				let res = await axios.get('api/user/all');
				if (res.code === 200) {
					this.users = res.data;
				} else {
					this.$message.error(res.message);
				}
			} catch (e) {
				this.$message.error('取得所有用户列表请求出错！', e.message);
			}

			// 关闭加载框
			loading.close();

		},

		toolAction(acName) {
			if (acName == "审核") {
				this.audit()
			} else if (acName == "") {
				// this.addbatch()
			} else {

			}
		},
		selectionChange(selection) {
			this.selection = selection
		},
		// 下载
		// downloadurl(index, row) {
		// 	return axios.defaults.baseURL + 'api/transform/download/' + row.id;
		// },
		//分配
		distribution(index, row) {
			this.index = index;
			this.dialogDistriFormVisible = true;
			this.transForm = deepCopy(row)
			// this.serviceForm.transformid = this.transForm.id
			// this.serviceForm.customerid = this.transForm.customerid

			this.serviceForm = this.transForm.service
			for (index in this.serviceForm) {
				this.$set(this.serviceForm[index], "enddate", "")
				this.$set(this.serviceForm[index], "leader", "")
				this.$set(this.serviceForm[index], "customerid", row.customerid)
			}
			this.$set(this.serviceForm[index], "enddate", "")
			this.$set(this.serviceCheckForm, "serviceForm", this.serviceForm)
			console.log(this.serviceCheckForm)
			console.log(this.serviceForm)
		},
		// 审核
		audit(index, row) {
			this.action = "edit"
			this.index = index;
			this.transForm = deepCopy(row)
			this.dialogAuditFormVisible = true;
		},
		//驳回
		nopassShowForm(index, row) {
			this.action = "nopass"
			this.index = index;
			this.transForm = deepCopy(row)
			this.dialogNoPassFormVisible = true;
			this.transForm.memo = ''
		},
		// 是否显示尾款审核
		showEnded(row) {
			if ((row.status == "已驳回" && row.formtype == "正常流转" )) {
				return false;
			} else if (row.amountpayin != row.amountreceivables) {
				return true;
			} else {
				return false;
			}
		},

		// 是否显示审核
		showAudit(index, row) {
			if (row.status == "已驳回" || row.status == "已分配" ) {
				return false;
			}
			else if (row.receiverid == localStorage.getItem('USERID') && row.receiverstatus == "待审核") {
				return true;
			} else if (row.supervisorid == localStorage.getItem('USERID') && row.supervisorstatus == "待审核") {
				return true;
			} else if (row.financeid == localStorage.getItem('USERID') && row.financestatus == "待审核") {
				return true;
			} else {
				return false;
			}
		},
		// 是否显示驳回
		showNopass(index, row) {
			if (row.status == "已驳回" || row.status == "已分配") {
				return false;
			}
			else if (row.receiverid == localStorage.getItem('USERID')) {
				return true;
			} else if (row.supervisorid == localStorage.getItem('USERID')) {
				return true;
			} else if (row.financeid == localStorage.getItem('USERID')) {
				return true;
			} else {
				return false;
			}
		},
		// 添加收款记录
		addRecorder(row) {
			this.action="addrecorder";
			this.transFormRecorderVisible = true
			this.mycustomerid = row.mycustomerid
			this.transFormRecorder.id=0
			this.transFormRecorder.transformid=row.id
			this.transFormRecorder.collectiondate=""
			// 现收尾款
			this.transFormRecorder.totalprice= row.amountreceivables - row.amountpayin
			this.transFormRecorder.amountreceivables= row.amountreceivables
			this.transFormRecorder.amountpayin= row.amountpayin + this.transFormRecorder.totalprice
			this.transFormRecorder.memo=""
			this.transFormRecorder.annex=[]
		},
		// 编辑收款记录
		editRecorder(index, row) {
			this.action="editrecorder"
			this.transFormRecorder = deepCopy(row)
			this.transFormRecorderVisible = true
		},
		// 删除收款记录
		delRecorder(index, row){
			this.$confirm('此操作将永久删除收款记录, 是否继续?', '提示', {
 			                confirmButtonText: '确定',
 			                cancelButtonText: '取消',
 			                type: 'warning'
            }).then(async () => {
					let res = await axios.put('api/transformrecorder/delete/' + row.id);
					if (res.code === 200) {
						this.query();
						this.$message.success(res.message);
					}else {
						this.$message.error(res.message);
					}	
	            }).catch((e) => {
	                if (e.message) this.Msg('error', e.message);
	            });
		},
		
		// 确认添加编辑收款记录
		async confirmRecorder() {
			this.$refs.transFormRecorder.validate(async valid => {
				if (valid) {
					// 显示加载框
					const loading = this.$loading(LOAD_STYLE);
					try {
						let res = null;
						if (this.action=="addrecorder") {
							res = await axios.put('api/transformrecorder/add', this.transFormRecorder);
						} else {
							res = await axios.put('api/transformrecorder/edit', this.transFormRecorder);
						}
						if (res.code === 200) {
							this.query();
							this.$message.success(res.message);
							this.transFormRecorderVisible = false
						} else {
							this.$message.error(res.message);
						}
					} catch (e) {
						this.$message.error('添加/编辑收款记录出错！', e.message);
					}
					// 关闭加载框
					loading.close();
				}
			})
		},

		// 取得所有主管
		async getAllLeader() {
			// 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
				let res = await axios.get('api/leader/all');
				if (res.code === 200) {
					this.members = res.data;
				} else {
					this.$message.error(res.message);
				}
			} catch (e) {
				this.$message.error('请求出错！', e.message);
			}

			// 关闭加载框
			loading.close();
			this.members.map((item, index) => {
				for (useritem in item.users) {
					this.leaders.push(
						Object.assign(item.users[useritem])
					)
				}
			});
			this.members = this.leaders
		},
		// 初始化团队成员列表
		async initMembers() {
			// 显示加载框
			const loading = this.$loading(LOAD_STYLE);
			try {
				let res = await axios.get('api/team/member/' + localStorage.getItem('USERID'));
				if (res.code === 200) {
					this.members = res.data;
				} else {
					this.$message.error(res.message);
				}
			} catch (e) {
				this.$message.error('初始化团队成员列表出错！', e.message);
			}

			// 关闭加载框
			loading.close();
		},

		// 设定表格当前页
		handleCurrentPageChange(selectedPageNo) {
			this.queryForm.pageNo = selectedPageNo
			// 加载数据页
			this.query()
		},
	},
	async mounted() {
		// 自动调整表格高度
		window.onresize = () => {
			return (() => {
				this.tableHeight = window.innerHeight - 180
			})()
		}
		//初始化会计部的子部门用户列表
		this.getAccountant();
		//初始化用户列表
		this.getAllUser();
		// 取得团队列表
		//this.initMembers();
		//取得主管列表
		//this.getAllLeader();

	}

});
